// Package gojob @author <chengjiang@buffalo-robot.com>
// @date 2023/4/10
// @note
package gojob

import (
	"fmt"
	"phm/internal/biz"
	"phm/internal/conf"
	"time"
)

var DefaultJobs map[string]JobFunc

type JobFunc func()

type JobService struct {
	radarCron *biz.RaRadarUseCase
}

func NewJobService(radarCron *biz.RaRadarUseCase) *JobService {
	job := &JobService{
		radarCron: radarCron,
	}
	//job.Init()
	return job
}

func (s *JobService) Init() {
	if conf.Config.Job.Switch {
		DefaultJobs = map[string]JobFunc{
			"TestCron1":             s.TestCron1,
			"TestCron2":             s.TestCron2,
			"SimulateRadarDataCron": s.SimulateRadarDataCron,
		}
	}
}

func (s *JobService) TestCron1() {
	fmt.Println(fmt.Sprintf("TestCron1 开始执行任务：%v", time.Now().Format("2006-01-02 15:04:05")))
}

func (s *JobService) TestCron2() {
	// meeting:
	fmt.Println(fmt.Sprintf("TestCron2 开始执行任务：%v", time.Now().Format("2006-01-02 15:04:05")))
}

func (s *JobService) SimulateRadarDataCron() {
	fmt.Println(fmt.Sprintf("SimulateRadarDataCron 开始执行任务：%v", time.Now().Format("2006-01-02 15:04:05")))
	start := time.Now()
	s.radarCron.SimulateRadarDataCron()
	end := time.Now()
	fmt.Println("执行耗时：", end.Sub(start))
}
